package com.example.administrator.x3picturetransliteration.Home.Presenter.Activity;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.example.administrator.x3picturetransliteration.Base.BasePresenter;
import com.example.administrator.x3picturetransliteration.Base.HttpGo;
import com.example.administrator.x3picturetransliteration.Bean.CheckBean;
import com.example.administrator.x3picturetransliteration.Bean.HttpDataBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import rx.subscriptions.CompositeSubscription;

/**
 * 检查更新
 * Created by Administrator on 2019/9/11.
 */

public class ToUpdatePresenter extends BasePresenter{

    public ToUpdatePresenter(Context context, CompositeSubscription mCompositeSubscription) {
        super(context, mCompositeSubscription);
    }

    /** 版本号 */
    public void Check(CheckBean mCheckBean, final Callback mCallback){

        Map<String,String> httpdata = new HashMap<>();

        httpdata.put("innerVersion",mCheckBean.getInnerVersion() + "");

        final List<CheckBean> CheckBeanList = new ArrayList<>();

        CheckBeanList.add(mCheckBean);

        mCompositeSubscription.add(

                mHttpGo.postSubscription("app_version/check", httpdata,null, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if(httpDataBean.getCode()==0){

                            if (httpDataBean.getData()!=null){

                                CheckBeanList.add(JSON.parseObject(httpDataBean.getData() + "", new TypeReference<CheckBean>() {}));
                            }
                        }

                        mCallback.getData(CheckBeanList);

                    }
                })
        );
    }

}
